package com.unytech.wisdomcommunity.mainfragment;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.unytech.wisdomcommunity.R;

/**
 * Created by zed on 2016/11/2/0027.
 */
public abstract class BaseFragment2 extends Fragment {

    private View mRootView;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // !!!! 这个判断很重要
        if (mRootView == null) {
            mRootView = inflater.inflate(R.layout.base_fragment, container, false);
            //ImageView imageView = (ImageView) mRootView.findViewById(R.id.fragment_base_title_iv);
            //TextView textView = (TextView) mRootView.findViewById(R.id.fragment_base_title_tv);
            ViewGroup childContainer = (ViewGroup) mRootView.findViewById(R.id.fragment_base_child_container);

            int childLayout = getContentLayoutRes();//让子类去实现,返回中间布局所需要的资源

            View childView = inflater.inflate(childLayout, childContainer, true);

            //initView(imageView, textView, childView);
            initView(childView);
        }
        return mRootView;
    }

    /*
    * 让子类去实现,返回中间布局所需要的资源
    * */
    protected abstract int getContentLayoutRes();
    /**
     * @param //imageView 给子类去设置可见性
     * @param //textView  给子类去设置文字
     * @param childView findViewById ，也就是  getContentLayoutRes 对应的布局
     */
    //protected abstract void initView(ImageView imageView, TextView textView, View childView);
    protected abstract void initView(View childView);

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }
}